<?php

use yii\helpers\Html;
use yii\grid\GridView;

/* @var $this yii\web\View */
/* @var $searchModel backend\modules\home\models\MhConfigSearch */
/* @var $dataProvider yii\data\ActiveDataProvider */

$this->title = '网站配置';
$this->params['breadcrumbs'][] = $this->title;
?>
<div class="mh-config-index">

    
    <?php // echo $this->render('_search', ['model' => $searchModel]); ?>

    <p>
        <?= Html::a('添加配置', ['create'], ['class' => 'btn btn-success']) ?>
    </p>

    <?= GridView::widget([
        'dataProvider' => $dataProvider,
        'filterModel' => $searchModel,
        'columns' => [
            ['class' => 'yii\grid\ActionColumn'],

            [
                'attribute' => 'id',
                'value' => 'id',
                'headerOptions' => ['width' => '50'],
            ],
            [
                'format' => 'raw',
                'attribute' => 'cid',
                'value' => function($model) {
                    if($model->cid == 1){
                        return '<span class="btn btn-xs btn-primary">基本设置</span>';
                    }elseif($model->cid == 2){
                        return '<span class="btn btn-xs btn-success">seo设置</span>';
                    }else{
                        return '';
                    }
                },
                'filter' => ['1' => '基本设置', '2' => 'seo设置'],
                'headerOptions' => ['width' => '100'],
            ],
            [
                'format' => 'raw',
                'attribute' => 'type',
                'value' => function($model) {
                    if($model->type == 'img'){
                        return '<span class="btn btn-xs btn-primary">图片</span>';
                    }else{
                        return '<span class="btn btn-xs btn-primary">文本</span>';
                    }
                },
                'filter' => ['text' => '文本', 'img' => '图片'],
                'headerOptions' => ['width' => '100'],
            ],
            //'key',
            'title',
            [
                'format' => 'raw',
                'attribute' => 'value',
                'value' => function($model){
                    return "<p style='width: 350px;overflow: hidden;white-space: nowrap;text-overflow: ellipsis;'>".$model->value."</p>";
                },
                'headerOptions' => ['width' => '350'],
            ],
            'remark',
            [
                'attribute' => 'sort',
                'value' => 'sort',
                'headerOptions' => ['width' => '50'],
            ],
            [
                'format' => 'raw',
                'attribute' => '快捷操作',
                'value' => function($model) {
                    if($model->type == 'img'){
                        return '<a href="/home/config/upload?id='.$model->id.'" class="btn btn-xs btn-info">上传</a>';
                    }else{
                        return '';
                    }
                }
            ],
        ],
    ]); ?>
</div>
